/*
 * Copyright 2010,2011 Michael Nitsche
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package de.mnit.basis.swt.dialog;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyleRange;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;

import de.mnit.basis.daten.konstant.position.POSITION_H;
import de.mnit.basis.fehler.system.F_Sys_InOut;
import de.mnit.basis.swt.anw.A_MN_Dialog;
import de.mnit.basis.swt.anw.A_MN_Gruppe;
import de.mnit.basis.swt.element.S_SWT_Komponente;
import de.mnit.basis.swt.element.steuer.SWT_Knopf;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.bild.SWT_TextEditor;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.bild.deko.SWT_Fenster;
import de.mnit.basis.swt.element.steuer.rollbar.gruppe.bild.deko.S_Fenster;
import de.mnit.basis.swt.grafik.icon.direkt.ICON;
import de.mnit.basis.swt.layout.LayoutGitter;

/**
 * @author Michael Nitsche
 * 01.04.2009	Erstellt
 */
public class Dialog_AnwInfo extends A_MN_Dialog<Dialog_AnwInfo, Object> {

	public static void main(String[] args) {
		start(Dialog_AnwInfo.class, "Test");
	}


	private final SWT_Knopf k_ok = new SWT_Knopf();
//	private final SWT_Label k_text = new SWT_Label().s1_Rahmen(true)/*.s1_Umbrechen()*/.s1_POSITION(POSITION_H.MITTE);
	private final SWT_TextEditor k_text;
	private final String text;
	private final StyleRange[] styles;
	private POSITION_H ausrichtung=POSITION_H.MITTE;
	private int dx=400, dy=450;


	public Dialog_AnwInfo(String text) {
		this(text,null, false);
	}

	public Dialog_AnwInfo(String text, StyleRange[] styles) {
		this(text, styles, false);
	}

	public Dialog_AnwInfo(String text, StyleRange[] styles, boolean scrollbar) {
		this.text=text;
		this.styles=styles;
		this.k_text = new SWT_TextEditor().s1_NurLesbar().s1_Rahmen(true).s1_Zeilenumbruch();
		if(scrollbar)
			this.k_text.s1_Rollbalken_V();
	}


	public void sAusrichtung(POSITION_H ausrichtung) {
		this.ausrichtung=ausrichtung;
	}

	public void sGroesse(int dx, int dy) {
		this.dx=dx;
		this.dy=dy;
	}

	protected S_Fenster<?> fenster(A_MN_Gruppe<?> instanz) throws F_Sys_InOut {
		return SWT_Fenster.neu(instanz, false, dx, dy, "Info", ICON.gib(24, "mn", "info.png"));
	}

	protected S_SWT_Komponente<?, ? extends Composite> layout() {
		return LayoutGitter.neu()
			.sSpaltenAnzahl(1)
			.sAussenabstand(5)
			.sZwischenraumV(10)
			.sKomponente(t.k_text)
				.sFlexibel()
			.sKomponente(t.k_ok)
				.sPositionH(POSITION_H.MITTE)
				.sBreite(120)
				.sHoehe(30)
			.fertig();
	}

	protected void initEvents() {
		t.k_ok.eAuswahl(new Listener(){
			public void handleEvent(Event event) {
				t.schliessen();
			}
		});
	}

	protected void initStyle() {
		t.k_ok.sBild(ICON.gib(24, "mn", "schliessen.png"));
		t.k_ok.sText("Schließen");


		int align=this.ausrichtung==POSITION_H.LINKS ? SWT.LEFT :
			this.ausrichtung==POSITION_H.RECHTS ? SWT.RIGHT :
			SWT.CENTER;

		this.k_text.swt().setAlignment(align);
		this.k_text.sText(text);

		if(this.styles!=null)
			this.k_text.swt().setStyleRanges(styles);

		t.k_text.sHintergrund(253,253,253);
	}

	protected Object gErgebnis2() {
		return null;
	}

}
